import threading
with threading.Lock():
    critical_section_code()